package com.zeus.base.smscenter.common.validate.impl;


import com.zeus.base.smscenter.common.security.MD5;
import com.zeus.base.smscenter.common.validate.ValidateHelper;
import com.zeus.base.smscenter.common.validate.model.ValidateStatus;
import com.zeus.base.smscenter.common.util.StringUtils;

import java.util.Map;

/**
 * 即时通验证
 *
 * @author lhs
 * @since 2016/5/9 17:13
 */
public class VComValidateHelper extends ValidateHelper {
    @Override
    public ValidateStatus validate(Map<String, Object> params) {
        ValidateStatus result = null;
        String supplierChannel = (String) params.get("supplierNo");
        if (supplierChannel.equals("1")) {
            String dbUserName = (String) params.get("dbUserName");
            String userName = (String) params.get("userName");
            String password = (String) params.get("password");
            String dbPassword = (String) params.get("dbPassword");
            if (StringUtils.isEmpty(userName)) {
                result = ValidateStatus.USERNAME_NOT_EXIST_ERROR;
            } else if (!dbUserName.equals(params.get("userName"))) {
                result = ValidateStatus.USERNAME_ERROR;
            } else if (StringUtils.isEmpty(password)) {
                result = ValidateStatus.PASSWORD_NOT_EXIST_ERROR;
            } else {
                if (MD5.generate(password, false).toUpperCase().equals(dbPassword)) {
                    result = ValidateStatus.SUCCESS;
                } else {
                    result = ValidateStatus.PASSWORD_ERROR;
                }
            }
        } else {
            if (getBaseValidateHelper() != null) {
                result = getBaseValidateHelper().validate(params);
            }
        }
        return result;
    }
}
